﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace LNUGame.Model
{
    /// <summary>
    /// Class to represent a player
    /// Constains the number of lives currently available and the base speed for moving and jumping
    /// </summary>
    class Player : MovingActor
    {
        private const int MOVE_RIGHT = 1;
        private const int MOVE_LEFT = -1;
        private const int MOVE_UP = -1;

        private const float SPEED_MOVING = 50f;
        private const float SPEED_JUMPING = 22.0f;

        private Vector2 m_gravity = new Vector2(0.0f, 7500.0f);

        private int m_numberOfLives = 3;

        /// <summary>
        /// Creates a new player object with a default size and starting position
        /// </summary>
        public Player()
        {
            m_size = new Vector2(0.6f, 0.95f);
            m_currentDirection = Direction.RIGHT;
            ResetPosition();
        }

        /// <summary>
        /// Updates the position and velocity of this instance
        /// </summary>
        /// <param name="a_elapsedTime"></param>
        internal void Update(float a_elapsedTime)
        {
            // Calculate the new position of the player
            m_centerBottomPosition += base.Velocity * a_elapsedTime + m_gravity * a_elapsedTime * a_elapsedTime;

            // Calculate the new (up/downwards) velocity of the player
            m_velocity = new Vector2(0.0f, base.Velocity.Y + m_gravity.Y * a_elapsedTime * a_elapsedTime);
        }

        /// <summary>
        /// Moves this instance to the right
        /// Changes facing to the right
        /// </summary>
        internal void MoveRight()
        {
            m_velocity = new Vector2(SPEED_MOVING * MOVE_RIGHT, base.Velocity.Y);
            m_currentDirection = Direction.RIGHT;
        }

        /// <summary>
        /// Moves this instance to the left
        /// Changes facing to the left
        /// </summary>
        internal void MoveLeft()
        {
            m_velocity = new Vector2(SPEED_MOVING * MOVE_LEFT, base.Velocity.Y);
            m_currentDirection = Direction.LEFT;
        }

        /// <summary>
        /// Moves this instance upwards to simulate a jump
        /// </summary>
        internal void Jump()
        {
            m_velocity = new Vector2(base.Velocity.X, SPEED_JUMPING * MOVE_UP);
        }

        /// <summary>
        /// Resets the position to the starting position
        /// </summary>
        internal void ResetPosition()
        {
            m_centerBottomPosition = new Vector2(2.0f, 10.0f);
        }

        /// <summary>
        /// Adds a life
        /// </summary>
        internal void AddLife()
        {
            m_numberOfLives++;
        }

        /// <summary>
        /// Removes a life
        /// </summary>
        internal void RemoveLife()
        {
            m_numberOfLives--;
        }

        /// <summary>
        /// Getter for the number of remaining lives
        /// </summary>
        public int RemainingLives
        {
            get
            {
                return m_numberOfLives;
            }
        }
    }
}